﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Basic4Net.OAWeb.Base;

namespace Basic4Net.OAWeb.Module_Base
{
    public partial class SubFactorPage : BasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                pagebind();
            }
        }

        private void pagebind()
        {
            this.rpt_SubFactor.DataSource = (new BusinessRules.SubFactor()).ListAll();
            this.rpt_SubFactor.DataBind();
        }

        protected void btnBind_Click(object sender, EventArgs e)
        {
            string msg = string.Empty;
            BusinessRules.SubFactor bll = new BusinessRules.SubFactor();
            foreach (RepeaterItem item in this.rpt_SubFactor.Items)
            {
                HiddenField hdf_RID = (HiddenField)item.FindControl("hdf_RID");
                HiddenField hdf_SubjectID = (HiddenField)item.FindControl("hdf_SubjectID");
                TextBox txt_Factor0 = (TextBox)item.FindControl("txt_Factor0");
                TextBox txt_Factor1 = (TextBox)item.FindControl("txt_Factor1");
                if (hdf_RID != null && hdf_SubjectID != null)
                {
                    Entities.t_SubFactor model = new Entities.t_SubFactor();
                    Entities.t_SubFactor model2 = new Entities.t_SubFactor();
                    model.SubjectID = int.Parse(hdf_SubjectID.Value);
                    model.SchoolMark = SchoolMark;
                    model2.SubjectID = int.Parse(hdf_SubjectID.Value);
                    model2.SchoolMark = SchoolMark;
                    if (int.Parse(hdf_RID.Value) == 0)
                    {
                        model.ClsType = 0;
                        model.Factor = float.Parse(txt_Factor0.Text);
                        bll.Add(model, ref msg);

                        model2.ClsType = 1;
                        model2.Factor = float.Parse(txt_Factor1.Text);
                        bll.Add(model2, ref msg);
                    }
                    else
                    {
                        model.ClsType = 0;
                        model.Factor = float.Parse(txt_Factor0.Text);
                        bll.Update(model, ref msg);

                        model2.ClsType = 1;
                        model2.Factor = float.Parse(txt_Factor1.Text);
                        bll.Update(model2, ref msg);
                    }
                }
            }
            pagebind();
        }
    }
}